package coml.jiyun.hp.gjtk_e.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import coml.jiyun.hp.gjtk_e.R;
import coml.jiyun.hp.gjtk_e.bean.ListBean;
import com.bumptech.glide.Glide;
import java.util.ArrayList;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {
    private Context context;
    private ArrayList<ListBean.DataBean.DatasBean> mData;

    public ListAdapter(Context context, ArrayList<ListBean.DataBean.DatasBean> mData) {
        this.context = context;
        this.mData = mData;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_list, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        final ListBean.DataBean.DatasBean datasBean = mData.get(position);
        holder.rv_title.setText(datasBean.getTitle());
        Glide.with(context).load(datasBean.getEnvelopePic()).into(holder.rv_img);

//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (onItemClickListener!=null){
//                    onItemClickListener.onItemClick(datasBean.getLink());
//                }
//            }
//        });
         holder.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (itemOnick != null){
                     itemOnick.dian(position);
                 }
             }
         });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView rv_img;
        private TextView rv_title;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            rv_img= itemView.findViewById(R.id.rv_img);
            rv_title= itemView.findViewById(R.id.rv_title);
        }
    }

    public interface itemOnick{

        void dian(int position);
    }

    private itemOnick itemOnick;

    public void setItemOnick(ListAdapter.itemOnick itemOnick) {
        this.itemOnick = itemOnick;
    }

}
